export const BASE_URL = 'http://localhost:8866'
export const BASE_IMAGES_URL = 'http://localhost:8866'

// export const BASE_URL = 'http://120.199.181.175:9998'
// export const BASE_IMAGES_URL = 'http://120.199.181.175:9000/jmimages/'

const request = ({
	url,
	data = {},
	method = 'get',
	header = {
		ContentType:'application/json' 
	},
}) => {
	let token = uni.getStorageSync('token') || '';
	
	if (!url) return;
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method,
			data,
			header: {
				"Authorization": token,
				...header
			},
			success: (res) => {
				if(res.data.code === 200 ){
					resolve(res.data)
				}else if(res.data.code === 403){
					uni.showToast({
						title:res.data,
						icon:'none'
					})
					
					uni.clearStorageSync("userInfo")
					uni.clearStorageSync("token")
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}else{
					uni.showToast({
						title:res.data.msg,
						icon:'none'
					})
				}
			},
			fail: (err) => {
				reject(err);
			}
		});
	})
}
export default request;

